package com.nopay.cdxphone.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.EditText;

import androidx.annotation.NonNull;

import com.nopay.cdxphone.R;

public class DialogCallTimeOut extends Dialog {

    public DialogCallTimeOut(@NonNull Activity context) {
        super(context, R.style.MyDialog);
    }

    private EditText etCallTimeOut;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_call_time_out);
        etCallTimeOut = findViewById(R.id.et_dialog_time_out);

        findViewById(R.id.tv_dialog_cancel).setOnClickListener(v -> dismiss());
        findViewById(R.id.tv_dialog_confirm).setOnClickListener(v -> {
            String timeoutStr = etCallTimeOut.getText().toString();
            int time = 8;
            try {
                time = Integer.parseInt(timeoutStr);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if(onCallTimeOutConfirmListener != null) onCallTimeOutConfirmListener.onCallTimeOutConfirm(time);

            dismiss();
        });
    }

    @Override
    public void dismiss() {
        super.dismiss();
        etCallTimeOut.setText("");
    }

    private OnCallTimeOutConfirmListener onCallTimeOutConfirmListener;

    public DialogCallTimeOut setOnCallTimeOutConfirmListener(OnCallTimeOutConfirmListener onCallTimeOutConfirmListener) {
        this.onCallTimeOutConfirmListener = onCallTimeOutConfirmListener;
        return this;
    }

    public interface OnCallTimeOutConfirmListener {

        void onCallTimeOutConfirm(int time);
    }
}
